package com.engine.zfhcxjsj.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.qdcyyy.duss.pushremind.util.ComUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-11-23
 * @Description: 对外提供接口推送信息
 * @ModifyLog:
 **/

public class WeaListInfoWeb {
    private static final String URL = "http://192.168.9.37:8998";

    /**
     * @Description: 推送供应商到期提醒\推送产品及代理商提醒待办事宜
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021-11-23
     */
    @GET
    @Path("/pushListDoing")
    @Produces({MediaType.TEXT_PLAIN})
    public String pushListDoing(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        RecordSet rs = new RecordSet();
        JSONArray dataList = new JSONArray();
        JSONObject resultData = new JSONObject();
        try {
            ResourceComInfo comInfo = new ResourceComInfo();
            String begdate = Util.null2String( request.getParameter( "begdate" ) );
            String enddate = Util.null2String( request.getParameter( "enddate" ) );
            String loginid = Util.null2String( request.getParameter( "loginid" ) );
            int userid = ComUtil.getHrmIdByLoginid( loginid );
            String type = Util.null2String( request.getParameter( "type" ) );
            String url0 = URL+"/spa/workflow/static4form/index.html?#/main/workflow/req?requestid=";
            String url1 = URL+"/spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=25&tabid=1&synergyRequestid=-1&formData=&synergyWorkflowid=1&tabTitle=5L6b5bqU5ZWG6LWE6LSo5Yiw5pyf5o-Q6YaS";
            String url2 = URL+"/spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=25&tabid=2&synergyRequestid=-1&formData=&synergyWorkflowid=2&tabTitle=5Lqn5ZOB6LWE6LSo5Yiw5pyf5o-Q6YaS";
            String url3 = URL+"/spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=7&tabid=1&synergyRequestid=-1&formData=&synergyWorkflowid=1&tabTitle=5b6F5Yqe";
            boolean flag1 = ComUtil.isLegalDate( begdate.length(), begdate, "yyyy-MM-dd" );
            boolean flag2 = ComUtil.isLegalDate( enddate.length(), enddate, "yyyy-MM-dd" );
            boolean flag3 = userid <= 0 ? false : true;
            if (!flag1 || !flag2) {
                resultData.put( "status", "ERROR" );
                resultData.put( "code", "500" );
                resultData.put( "msg", "日期格式错误，请检查日期参数(yyyy-MM-dd)" );
            }
            if (!flag3) {
                resultData.put( "status", "ERROR" );
                resultData.put( "code", "500" );
                resultData.put( "msg", "人员ID不存在，请检查人员ID参数" );
            }
            if (flag1 && flag2 && flag3) {
                String sql = " select (case requestlevel  when 0 then 0 when 1 then 1 when 2 then 2 else -1 end ) as requestlevelorder,  t1.requestid,t1.requestmark,t1.createdate, \n" +
                        " t1.createtime,t1.creater, t1.creatertype, t1.workflowid, t1.requestname, t1.requestnamenew, t1.status,t1.requestlevel,t1.currentnodeid,t2.viewtype,\n" +
                        " t2.userid,t2.receivedate,t2.receivetime,t2.isremark,t2.nodeid,t2.agentorbyagentid,t2.agenttype,t2.isprocessed  ,t1.seclevel,'0' as systype,t2.workflowtype,\n" +
                        " t2.isbereject,t2.takisremark,t1.requestnamehtmlnew,t2.viewDate,t2.viewTime,t1.lastFeedBackDate,t1.lastFeedBackTime,t2.needwfback,t1.lastFeedBackOperator\n" +
                        "   from workflow_requestbase t1,workflow_currentoperator t2,workflow_base t3  where t1.requestid = t2.requestid and t1.workflowid=t3.id and t2.userid in (" + userid + ") \n" +
                        "   and t2.usertype=0 and (isnull(t1.currentstatus,-1) = -1 or (isnull(t1.currentstatus,-1)=0 and t1.creater in (" + userid + ")))  \n" +
                        "   and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  and t2.workflowtype in(" + type + ") and t1.createdate between '" + begdate + "' and '" + enddate + "'\n" +
                        "   and ((t2.isremark='0' and (t2.takisremark is null or t2.takisremark=0 )) or t2.isremark in('1','5','8','9','7','11')) and t2.islasttimes=1 \n" +
                        "   and (  (t2.isremark not in('1','8','9','11') or (t2.isremark='1' and t2.takisremark='2'))  )  and (isprocessing = '' or isprocessing is null)  \n" +
                        "   and t3.isvalid in('1','3') order by receivedate desc ,receivetime desc ";
                rs.executeQuery( sql );
                int count = 1;
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    String requestid = Util.null2String( rs.getString( "requestid" ) );
                    data.put( "requestid",requestid);//流程requestid
                    data.put( "requestmark", Util.null2String( rs.getString( "requestmark" ) ) );//请求说明
                    data.put( "createdate", Util.null2String( rs.getString( "createdate" ) ) );//创建日期
                    data.put( "createtime", Util.null2String( rs.getString( "createtime" ) ) );//创建时间
                    data.put( "creater", Util.null2String( rs.getString( "creater" ) ) );//创建人
                    data.put( "workflowid", Util.null2String( rs.getString( "workflowid" ) ) );//流程id
                    data.put( "requestname", Util.null2String( rs.getString( "requestname" ) ) );//流程名称
                    data.put( "requestnamenew", Util.null2String( rs.getString( "requestnamenew" ) ) );//变更后流程名称
                    data.put( "status", Util.null2String( rs.getString( "status" ) ) );//请求状态
                    data.put( "requestlevel", Util.null2String( rs.getString( "requestlevel" ) ) );//请求级别0：正常；1：重要；2：紧急
                    data.put( "viewtype", Util.null2String( rs.getString( "viewtype" ) ) );//查看标志
                    data.put( "userid", Util.null2String( rs.getString( "userid" ) ) );//用户id
                    data.put( "receivedate", Util.null2String( rs.getString( "receivedate" ) ) );//接收到的日期
                    data.put( "receivetime", Util.null2String( rs.getString( "receivetime" ) ) );//接收到的时间
                    data.put( "isremark", Util.null2String( rs.getString( "isremark" ) ) );//操作类型
                    data.put( "seclevel", Util.null2String( rs.getString( "seclevel" ) ) );//流程密级
                    data.put( "workflowtype", Util.null2String( rs.getString( "workflowtype" ) ) );//流程类型
                    data.put( "viewDate", Util.null2String( rs.getString( "viewDate" ) ) );//查看日期
                    data.put( "viewTime", Util.null2String( rs.getString( "viewTime" ) ) );//查看时间
                    data.put( "url", url0+requestid );//查看时间
                    data.put( "serialNumber", count );
                    dataList.add( data );
                    count++;
                }
                if (dataList.size() > 0) {
                    resultData.put( "dataList", dataList );
                    String url = "";
                    if("2".equals( type )){
                        url =url3;
                    }else if("3".equals( type )){
                        url =url1;
                    }else if("3".equals( type )){
                        url =url2;
                    }
                    resultData.put( "more", url );
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                } else {
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                    resultData.put( "msg", "未查询到相关推送信息" );
                }
            }
            apidatas.put( "result", resultData );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "error_message", "请求异常" );
        }
        return JSONObject.toJSONString( apidatas );
    }
    /**
     * @Description: 推送供应商到期提醒\推送产品及代理商提醒已办事宜
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021-11-23
     */
    @GET
    @Path("/pushListDone")
    @Produces({MediaType.TEXT_PLAIN})
    public String pushListDone(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        RecordSet rs = new RecordSet();
        JSONArray dataList = new JSONArray();
        JSONObject resultData = new JSONObject();
        try {
            ResourceComInfo comInfo = new ResourceComInfo();
            String begdate = Util.null2String( request.getParameter( "begdate" ) );
            String enddate = Util.null2String( request.getParameter( "enddate" ) );
            String loginid = Util.null2String( request.getParameter( "loginid" ) );
            int userid = ComUtil.getHrmIdByLoginid( loginid );
            String type = Util.null2String( request.getParameter( "type" ) );
            String url0 = URL+"/spa/workflow/static4form/index.html?#/main/workflow/req?requestid=";
            String url1 = URL+"/spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=25&tabid=1&synergyRequestid=-1&formData=&synergyWorkflowid=1&tabTitle=5L6b5bqU5ZWG6LWE6LSo5Yiw5pyf5o-Q6YaS";
            String url2 = URL+"/spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=25&tabid=2&synergyRequestid=-1&formData=&synergyWorkflowid=2&tabTitle=5Lqn5ZOB6LWE6LSo5Yiw5pyf5o-Q6YaS";
            String url3 = URL+" /spa/workflow/static/index.html#/main/workflow/queryFlowResult?fromwhere=jsonFilter&eid=7&tabid=3&synergyRequestid=-1&formData=&synergyWorkflowid=3&tabTitle=5bey5Yqe";
            boolean flag1 = ComUtil.isLegalDate( begdate.length(), begdate, "yyyy-MM-dd" );
            boolean flag2 = ComUtil.isLegalDate( enddate.length(), enddate, "yyyy-MM-dd" );
            boolean flag3 = userid <= 0 ? false : true;
            if (!flag1 || !flag2) {
                resultData.put( "status", "ERROR" );
                resultData.put( "code", "500" );
                resultData.put( "msg", "日期格式错误，请检查日期参数(yyyy-MM-dd)" );
            }
            if (!flag3) {
                resultData.put( "status", "ERROR" );
                resultData.put( "code", "500" );
                resultData.put( "msg", "人员ID不存在，请检查人员ID参数" );
            }
            if (flag1 && flag2 && flag3) {
                String sql = " select requestid,requestmark,createdate, createtime,creater, creatertype, workflowid, requestname, requestnamenew, status,\n" +
                        " requestlevel,currentnodeid,viewtype,userid,receivedate,receivetime,isremark,nodeid,agentorbyagentid,agenttype,isprocessed ,\n" +
                        " operatedate,operatetime,systype,workflowtype,isbereject,takisremark,requestnamehtmlnew,viewDate,viewTime,lastFeedBackDate,\n" +
                        " lastFeedBackTime,needwfback,lastFeedBackOperator,operatedateNew,operatetimeNew  from \n" +
                        " (select  (case requestlevel   when 0 then 0 when 1 then 1 when 2 then 2 else -1 end ) as requestlevelorder, \n" +
                        "  t1.requestid,t1.requestmark,t1.createdate, t1.createtime,t1.creater, t1.creatertype, t1.workflowid, t1.requestname, \n" +
                        "  t1.requestnamenew, t1.status,t1.requestlevel,t1.currentnodeid,t2.viewtype,t2.userid,t2.receivedate,t2.receivetime,\n" +
                        "  t2.isremark,t2.nodeid,t2.agentorbyagentid,t2.agenttype,t2.isprocessed , (case  WHEN t2.operatedate IS NULL  THEN t2.receivedate ELSE t2.operatedate END)\n" +
                        "  operatedate , (case  WHEN t2.operatetime IS NULL  THEN t2.receivetime ELSE t2.operatetime END) operatetime ,t1.seclevel,'0' as systype,\n" +
                        "  t2.workflowtype,t2.isbereject,t2.takisremark,t1.requestnamehtmlnew,t2.viewDate,t2.viewTime,t1.lastFeedBackDate,t1.lastFeedBackTime,\n" +
                        "  t2.needwfback,t1.lastFeedBackOperator,t2.operatedate as operatedateNew,t2.operatetime as operatetimeNew  from workflow_requestbase t1,workflow_currentoperator t2,\n" +
                        "  workflow_base t3 where t1.requestid = t2.requestid and t1.workflowid=t3.id and t2.userid in ("+userid+") and t2.usertype=0 \n" +
                        "  and (isnull(t1.currentstatus,-1) = -1 or (isnull(t1.currentstatus,-1)=0 and t1.creater in ("+userid+"))) and t2.workflowtype in("+type+") and t1.createdate between '" + begdate + "' and '" + enddate + "'\n" +
                        "  and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  and (t2.isremark in('2','4') or (t2.isremark='0' and t2.takisremark =-2))\n" +
                        "  and t3.isvalid in('1','3') ) t1   order by t1.operatedate,t1.operatetime  Desc ";
                rs.executeQuery( sql );
                int count = 1;
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    String requestid = Util.null2String( rs.getString( "requestid" ) );
                    data.put( "requestid",requestid );//流程requestid
                    data.put( "requestmark", Util.null2String( rs.getString( "requestmark" ) ) );//请求说明
                    data.put( "createdate", Util.null2String( rs.getString( "createdate" ) ) );//创建日期
                    data.put( "createtime", Util.null2String( rs.getString( "createtime" ) ) );//创建时间
                    data.put( "creater", Util.null2String( rs.getString( "creater" ) ) );//创建人
                    data.put( "workflowid", Util.null2String( rs.getString( "workflowid" ) ) );//流程id
                    data.put( "requestname", Util.null2String( rs.getString( "requestname" ) ) );//流程名称
                    data.put( "requestnamenew", Util.null2String( rs.getString( "requestnamenew" ) ) );//变更后流程名称
                    data.put( "status", Util.null2String( rs.getString( "status" ) ) );//请求状态
                    data.put( "requestlevel", Util.null2String( rs.getString( "requestlevel" ) ) );//请求级别0：正常；1：重要；2：紧急
                    data.put( "viewtype", Util.null2String( rs.getString( "viewtype" ) ) );//查看标志
                    data.put( "userid", Util.null2String( rs.getString( "userid" ) ) );//用户id
                    data.put( "receivedate", Util.null2String( rs.getString( "receivedate" ) ) );//接收到的日期
                    data.put( "receivetime", Util.null2String( rs.getString( "receivetime" ) ) );//接收到的时间
                    data.put( "isremark", Util.null2String( rs.getString( "isremark" ) ) );//操作类型
                    data.put( "workflowtype", Util.null2String( rs.getString( "workflowtype" ) ) );//流程类型
                    data.put( "viewDate", Util.null2String( rs.getString( "viewDate" ) ) );//查看日期
                    data.put( "viewTime", Util.null2String( rs.getString( "viewTime" ) ) );//查看时间
                    data.put( "url", url0+requestid);//查看时间
                    data.put( "serialNumber", count );
                    dataList.add( data );
                    count++;
                }
                if (dataList.size() > 0) {
                    resultData.put( "dataList", dataList );
                    String url = "";
                    if("2".equals( type )){
                        url =url3;
                    }else if("3".equals( type )){
                        url =url1;
                    }else if("3".equals( type )){
                        url =url2;
                    }
                    resultData.put( "more", url );
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                } else {
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                    resultData.put( "msg", "未查询到相关推送信息" );
                }
            }
            apidatas.put( "result", resultData );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "error_message", "请求异常" );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 推送供应商管理台账信息
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021-11-23
     */
    @GET
    @Path("/pushSupplierLedger")
    @Produces({MediaType.TEXT_PLAIN})
    public String pushSupplierLedger(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        JSONArray dataList = new JSONArray();
        JSONObject resultData = new JSONObject();
        boolean flag1 = true;
        boolean flag2 = true;
        boolean flag3 = true;
        try {
            ResourceComInfo comInfo = new ResourceComInfo();
            String begdate = Util.null2String( request.getParameter( "begdate" ) );
            String enddate = Util.null2String( request.getParameter( "enddate" ) );
            String loginid = Util.null2String( request.getParameter( "loginid" ) );
            int userid = ComUtil.getHrmIdByLoginid( loginid );
            String formtable = "uf_gysgld";
            String url = URL+"/spa/cube/index.html#/main/cube/search?customid=2";
            if (!"".equals( begdate ) && !"".equals( enddate )) {
                flag1 = ComUtil.isLegalDate( begdate.length(), begdate, "yyyy-MM-dd" );
                flag2 = ComUtil.isLegalDate( enddate.length(), enddate, "yyyy-MM-dd" );
                if (!flag1 || !flag2) {
                    resultData.put( "status", "ERROR" );
                    resultData.put( "code", "500" );
                    resultData.put( "msg", "日期格式错误，请检查日期参数(yyyy-MM-dd)" );
                }
            }
            if (!"".equals( userid )) {
                flag3 = userid <= 0 ? false : true;
                if (!flag3) {
                    resultData.put( "status", "ERROR" );
                    resultData.put( "code", "500" );
                    resultData.put( "msg", "人员ID不存在，请检查人员ID参数" );
                }
            }

            if (flag1 && flag2 && flag3) {
                String sql = "select id,gysmcqc,yyzzxydm,yyksqx,yyjsqx,ylqxjyxkzcbh,ylqxjyxkzcbhyxksqx," +
                        "ylqxjyxkzcbhyxjsqx,frxm,sqwtr,sqkssj,sqjssj,htksrq,htjsrq,modedatacreatedate,modedatacreatetime,modedatacreater" +
                        " from " + formtable +
                        " where modedatacreatedate between '" + begdate + "' and '" + enddate + "' " +
                        " and modedatacreater in(" + userid + ") " +
                        " order by modedatacreatedate,modedatacreatetime";
                rs.executeQuery( sql );
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    String mainid = Util.null2String( rs.getString( "id" ) );
                    data.put( "gysmcqc", Util.null2String( rs.getString( "gysmcqc" ) ) );
                    data.put( "yyzzxydm", Util.null2String( rs.getString( "yyzzxydm" ) ) );
                    data.put( "yyksqx", Util.null2String( rs.getString( "yyksqx" ) ) );
                    data.put( "yyjsqx", Util.null2String( rs.getString( "yyjsqx" ) ) );
                    data.put( "ylqxjyxkzcbh", Util.null2String( rs.getString( "ylqxjyxkzcbh" ) ) );
                    data.put( "ylqxjyxkzcbhyxksqx", Util.null2String( rs.getString( "ylqxjyxkzcbhyxksqx" ) ) );
                    data.put( "frxm", Util.null2String( rs.getString( "frxm" ) ) );
                    data.put( "sqwtr", Util.null2String( rs.getString( "sqwtr" ) ) );
                    data.put( "sqkssj", Util.null2String( rs.getString( "sqkssj" ) ) );
                    data.put( "sqjssj", Util.null2String( rs.getString( "sqjssj" ) ) );
                    data.put( "htksrq", Util.null2String( rs.getString( "htksrq" ) ) );
                    data.put( "htjsrq", Util.null2String( rs.getString( "htjsrq" ) ) );
                    data.put( "createdate", Util.null2String( rs.getString( "modedatacreatedate" ) ) );
                    data.put( "createtime", Util.null2String( rs.getString( "modedatacreatetime" ) ) );
                    data.put( "creater", Util.null2String( rs.getString( "modedatacreater" ) ) );
                    JSONArray childList = new JSONArray();
                    rs1.executeQuery( "select fdazczmc,rkmc,ggxh,sfgw,dw,sbjg,yyghj,cppp,cpzczbh,cpzczbhpzrq,cpzczbhyxq " +
                            "from " + formtable + "_dt1 where mainid=" + mainid );
                    while (rs1.next()) {
                        JSONObject childData = new JSONObject();
                        childData.put( "fdazczmc", Util.null2String( rs1.getString( "fdazczmc" ) ) );
                        childData.put( "rkmc", Util.null2String( rs1.getString( "rkmc" ) ) );
                        childData.put( "ggxh", Util.null2String( rs1.getString( "ggxh" ) ) );
                        childData.put( "sfgw", Util.null2String( rs1.getString( "sfgw" ) ) );
                        childData.put( "dw", Util.null2String( rs1.getString( "dw" ) ) );
                        childData.put( "sbjg", Util.null2String( rs1.getString( "sbjg" ) ) );
                        childData.put( "yyghj", Util.null2String( rs1.getString( "yyghj" ) ) );
                        childData.put( "cppp", Util.null2String( rs1.getString( "cppp" ) ) );
                        childData.put( "cpzczbh", Util.null2String( rs1.getString( "cpzczbh" ) ) );
                        childData.put( "cpzczbhpzrq", Util.null2String( rs1.getString( "cpzczbhpzrq" ) ) );
                        childData.put( "cpzczbhyxq", Util.null2String( rs1.getString( "cpzczbhyxq" ) ) );
                        childList.add( childData );
                    }
                    data.put( "childList", childList );
                    dataList.add( data );
                }
                if (dataList.size() > 0) {
                    resultData.put( "dataList", dataList );
                    resultData.put( "more", url );
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                } else {
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                    resultData.put( "msg", "未查询到相关推送信息" );
                }
            }
            apidatas.put( "result", resultData );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "error_message", "请求异常" );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 推送合同管理台账信息
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021-11-23
     */
    @GET
    @Path("/pushContractLedger")
    @Produces({MediaType.TEXT_PLAIN})
    public String pushContractLedger(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        RecordSet rs = new RecordSet();
        JSONArray dataList = new JSONArray();
        JSONObject resultData = new JSONObject();
        boolean flag1 = true;
        boolean flag2 = true;
        boolean flag3 = true;
        try {
            ResourceComInfo comInfo = new ResourceComInfo();
            String begdate = Util.null2String( request.getParameter( "begdate" ) );
            String enddate = Util.null2String( request.getParameter( "enddate" ) );
            String loginid = Util.null2String( request.getParameter( "loginid" ) );
            int userid = ComUtil.getHrmIdByLoginid( loginid );
            String formtable = "uf_htgltz";
            String url = URL+"/spa/cube/index.html#/main/cube/search?customid=1";
            if (!"".equals( begdate ) && !"".equals( enddate )) {
                flag1 = ComUtil.isLegalDate( begdate.length(), begdate, "yyyy-MM-dd" );
                flag2 = ComUtil.isLegalDate( enddate.length(), enddate, "yyyy-MM-dd" );
                if (!flag1 || !flag2) {
                    resultData.put( "status", "ERROR" );
                    resultData.put( "code", "500" );
                    resultData.put( "msg", "日期格式错误，请检查日期参数(yyyy-MM-dd)" );
                }
            }
            if (!"".equals( userid )) {
                flag3 = userid <= 0 ? false : true;
                if (!flag3) {
                    resultData.put( "status", "ERROR" );
                    resultData.put( "code", "500" );
                    resultData.put( "msg", "人员ID不存在，请检查人员ID参数" );
                }
            }

            if (flag1 && flag2 && flag3) {
                String sql = "select id,htmc,htbh,zjedwy,fkfs,qdsj,htzzsj,wbq,xz,qdhht,sqks,modedatacreatedate,modedatacreatetime,modedatacreater" +
                        " from " + formtable +
                        " where modedatacreatedate between '" + begdate + "' and '" + enddate + "' "+
                        " and modedatacreater in(" + userid + ") "+
                        " order by modedatacreatedate,modedatacreatetime";
                rs.executeQuery( sql );
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    data.put( "id", Util.null2String( rs.getString( "id" ) ) );
                    data.put( "htmc", Util.null2String( rs.getString( "htmc" ) ) );//合同名称
                    data.put( "htbh", Util.null2String( rs.getString( "htbh" ) ) );//合同编号
                    data.put( "zjedwy", Util.null2String( rs.getString( "zjedwy" ) ) );//总金额(元)
                    data.put( "fkfs", Util.null2String( rs.getString( "fkfs" ) ) );//付款方式
                    data.put( "qdsj", Util.null2String( rs.getString( "qdsj" ) ) );//签订时间
                    data.put( "htzzsj", Util.null2String( rs.getString( "htzzsj" ) ) );//合同终止时间
                    data.put( "wbq", Util.null2String( rs.getString( "wbq" ) ) );//维保期
                    data.put( "xz", Util.null2String( rs.getString( "xz" ) ) );//性质
                    data.put( "qdhht", Util.null2String( rs.getString( "qdhht" ) ) );//签订后合同
                    data.put( "sqks", Util.null2String( rs.getString( "sqks" ) ) );//申请科室
                    data.put( "createdate", Util.null2String( rs.getString( "modedatacreatedate" ) ) );
                    data.put( "createtime", Util.null2String( rs.getString( "modedatacreatetime" ) ) );
                    data.put( "creater", Util.null2String( rs.getString( "modedatacreater" ) ) );
                    dataList.add( data );
                }
                if (dataList.size() > 0) {
                    resultData.put( "dataList", dataList );
                    resultData.put( "more", url );
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                } else {
                    resultData.put( "status", "SUCCESS" );
                    resultData.put( "code", "200" );
                    resultData.put( "msg", "未查询到相关推送信息" );
                }
            }
            apidatas.put( "result", resultData );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "error_message", "请求异常" );
        }
        return JSONObject.toJSONString( apidatas );
    }
}
